package com.qaml.mes.device.controller;


import com.earth.output.OutputMessage;
import com.qaml.mes.device.utils.OssUploadFileUtil;
import com.qaml.mes.device.vo.eqp.UploadFileVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName FileUploadController
 * @Description 文件上传控制器
 * @Author leikai
 * @Date 2024/3/5 0005 11:27
 * @Version 1.0
 */
@Api(tags = "文件上传")
@RestController
@RequestMapping(value = "/file")
public class FileUploadController {

    @ApiOperation("文件上传(App和Web均有)")
    @PostMapping(value = "/upload")
    public OutputMessage<UploadFileVO> uploadFile(@RequestParam("file") MultipartFile multipartFile) {
        UploadFileVO uploadFileVO = new UploadFileVO();
        uploadFileVO.setFileName(multipartFile.getOriginalFilename());
        String fileUrl = OssUploadFileUtil.fileUpload(multipartFile);
        uploadFileVO.setFileUrl(fileUrl);
        return OutputMessage.success(uploadFileVO);
    }
}